import java.util.*;

public class MListTest {
    static final Scanner sc = new Scanner(System.in);

    static public void main(String [] args) {
        // int num;
        // char num;
        // double num;
        // String num;
        String name;
        // MList darr = new MList(); //测试链表
        Darr darr = new Darr();     //测试数组
        DataCompare cmp = new DataCompare() {
            public int compare(Object d1, Object d2) {
                return ((String)d2).compareTo((String)d1);
            }
        };

        while (true) {
            System.out.printf("请输入数据(-1: 退出): ");
            // num = sc.nextInt();
            // num = sc.next().charAt(0);
            // num = sc.nextDouble();
            name = sc.nextLine();
            // if (num == -1)
            // if (num == 'q')
            // if (num > -0.0001 && num < 0.0001)
            // if (num.equals("exit"))
            if (name.equals("exit"))
                break;
            darr.append(name);
            // darr.prepend(name);
        }
        name = "INSERT";
        darr.add(3, name);
        System.out.printf("len = %d\n", darr.len());

        //测试用户输入数据及插入数据
        System.out.printf("input data: ");
        while ((name = (String)darr.getNext()) != null) {
            System.out.printf("%s ", name);
        }
        System.out.println();

        //测试排序
        darr.sort(cmp);
        System.out.printf("sort data: ");
        while ((name = (String)darr.getNext()) != null) {
            System.out.printf("%s ", name);
        }
        System.out.println();

        //测试删除
        name = "aaa";
        darr.deleteAll(name, cmp);
        // darr.deleteNum(3, name, cmp);
        System.out.printf("delete data: ");
        while ((name = (String)darr.getNext()) != null) {
            System.out.printf("%s ", name);
        }
        System.out.println();

        // MList findObj = (MList)darr.findAll(name, cmp);

        /*
         * while ((name = (String)findObj.getNext()) != null) {
         *     System.out.printf("%s\n", name);
         * }
         */
    }
}
